home *** CD-ROM | disk | FTP | other *** search
/ Ham Radio 2000 / Ham Radio 2000.iso / ham2000 / tcp_ip / os2 / pmnos11s / pppdump.c < prev    next >
C/C++ Source or Header  |  1993-07-30  |  3KB  |  105 lines

  1. /*
  2.  *    PPPDUMP.C
  3.  *
  4.  *    12-89    -- Katie Stevens (dkstevens@ucdavis.edu)
  5.  *           UC Davis, Computing Services
  6.  *    PPP.08    05-90    [ks] improve tracing reports
  7.  *    PPP.09  05-90    [ks] add UPAP packet reporting
  8.  *    PPP.14    08-90    [ks] change UPAP to PAP for consistency with RFC1172
  9.  *    PPP.15    09-90    [ks] update to KA9Q NOS v900828
  10.  *    Jan 91    [Bill Simpson] small changes to match rewrite of PPP
  11.  *    Aug 91    [Bill Simpson] fixed some buffer loss
  12.  */
  13. #include <stdio.h>
  14. #include "global.h"
  15. #include "mbuf.h"
  16. #include "iface.h"
  17. #include "internet.h"
  18. #include "ppp.h"
  19. #include "trace.h"
  20.  
  21. #ifdef TURBOC_SWITCH_BUG
  22. #pragma option -G-
  23. #endif
  24.  
  25. /* dump a PPP packet */
  26. void
  27. ppp_dump(ip,bpp,unused)
  28. struct iface  *ip;
  29. struct mbuf **bpp;
  30. int unused;
  31. {
  32.     struct ppp_hdr hdr;
  33.     struct mbuf *tbp;
  34.  
  35.     prtTrace(ip,"PPP: len %3u\t", len_p(*bpp));
  36.  
  37.     /* HDLC address and control fields may be compressed out */
  38.     if ((byte_t)(*bpp)->data[0] != HDLC_ALL_ADDR) {
  39.         prtTrace(ip,"(compressed ALL/UI)\t");
  40.     } else if ((byte_t)(*bpp)->data[1] != HDLC_UI) {
  41.         prtTrace(ip,"(missing UI!)\t");
  42.     } else {
  43.         /* skip address/control fields */
  44.         pull16(bpp);
  45.     }
  46.  
  47.     /* Initialize the expected header */
  48.     hdr.addr = HDLC_ALL_ADDR;
  49.     hdr.control = HDLC_UI;
  50.     hdr.protocol = PULLCHAR(bpp);
  51.  
  52.     /* First byte of PPP protocol field may be compressed out */
  53.     if ( hdr.protocol & 0x01 ) {
  54.         prtTrace(ip,"compressed ");
  55.     } else {
  56.         hdr.protocol = (hdr.protocol << 8) | PULLCHAR(bpp);
  57.  
  58.         /* Second byte of PPP protocol field must be odd */
  59.         if ( !(hdr.protocol & 0x01) ) {
  60.             prtTrace(ip, "(not odd!) " );
  61.         }
  62.     }
  63.  
  64.     prtTrace(ip,"protocol: ");
  65.     switch(hdr.protocol){
  66.         case PPP_IP_PROTOCOL:
  67.             prtTrace(ip,"IP\n");
  68.             ip_dump(ip,bpp,1);
  69.             break;
  70.         case PPP_IPCP_PROTOCOL:
  71.             prtTrace(ip,"IPCP\n");
  72.             break;
  73.         case PPP_LCP_PROTOCOL:
  74.             prtTrace(ip,"LCP\n");
  75.             break;
  76.         case PPP_PAP_PROTOCOL:
  77.             prtTrace(ip,"PAP\n");
  78.             break;
  79.         case PPP_COMPR_PROTOCOL:
  80.             prtTrace(ip,"VJ Compressed TCP/IP\n");
  81.             vjcomp_dump(ip,bpp,0);
  82.             break;
  83.         case PPP_UNCOMP_PROTOCOL:
  84.             prtTrace(ip,"VJ Uncompressed TCP/IP\n");
  85.             /* Get our own copy so we can mess with the data */
  86.             if ( (tbp = copy_p(*bpp, len_p(*bpp))) == NULLBUF)
  87.                 return;
  88.  
  89.             prtTrace(ip,"\tconnection 0x%02x\n",
  90.                 tbp->data[9]);        /* FIX THIS! */
  91.             /* Restore the bytes used with Uncompressed TCP */
  92.             tbp->data[9] = TCP_PTCL;    /* FIX THIS! */
  93.             ip_dump(ip,&tbp,1);
  94.             free_p(tbp);
  95.             break;
  96.         default:
  97.             prtTrace(ip,"unknown 0x%04x\n",hdr.protocol);
  98.             break;
  99.     }
  100. }
  101.  
  102. #ifdef TURBOC_SWITCH_BUG
  103. #pragma option -G
  104. #endif
  105.